﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => MST_BUYER_LEVEL
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 12:08:06
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class MstBuyerLevelDal 
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static MstBuyerLevelDal _dal;

        private System.String sql = "";


        public static MstBuyerLevelDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new MstBuyerLevelDal();

            return _dal;
        }

        public IEnumerable<Prop.MstBuyerLevel> Select(Prop.MstBuyerLevel obj)
        {
            IEnumerable<Prop.MstBuyerLevel> entities = new List<Prop.MstBuyerLevel>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.LEVEL_NO))
                    {
                        concast.Append(" AND LEVEL_NO=:LEVEL_NO ");
                        hashtable.Add(":LEVEL_NO", obj.LEVEL_NO);
                    }

                    if (!String.IsNullOrEmpty(obj.LEVEL_DESCRIPTION))
                    {
                        concast.Append(" AND LEVEL_DESCRIPTION=:LEVEL_DESCRIPTION ");
                        hashtable.Add(":LEVEL_DESCRIPTION", obj.LEVEL_DESCRIPTION);
                    }

                    if (!Information.IsNothing(obj.SEQ_NO))
                    {
                        concast.Append(" AND SEQ_NO=:SEQ_NO ");
                        hashtable.Add(":SEQ_NO", obj.SEQ_NO);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                }
                sql = System.String.Format(@" SELECT LEVEL_NO ,LEVEL_DESCRIPTION ,SEQ_NO ,COMPANY_CODE  FROM MST_BUYER_LEVEL");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.MstBuyerLevel>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.MstBuyerLevel obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO MST_BUYER_LEVEL(LEVEL_NO ,LEVEL_DESCRIPTION ,SEQ_NO ,COMPANY_CODE )
					VALUES(:LEVEL_NO ,:LEVEL_DESCRIPTION ,:SEQ_NO ,:COMPANY_CODE ");

                hashtable = new Hashtable();
                hashtable.Add(":LEVEL_NO", obj.LEVEL_NO);
                hashtable.Add(":LEVEL_DESCRIPTION", obj.LEVEL_DESCRIPTION);
                hashtable.Add(":SEQ_NO", obj.SEQ_NO);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.MstBuyerLevel obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE MST_BUYER_LEVEL
					SET
					LEVEL_NO=:LEVEL_NO,
					LEVEL_DESCRIPTION=:LEVEL_DESCRIPTION,
					SEQ_NO=:SEQ_NO,
					COMPANY_CODE=:COMPANY_CODE");

                hashtable = new Hashtable();
                hashtable.Add(":LEVEL_NO", obj.LEVEL_NO);
                hashtable.Add(":LEVEL_DESCRIPTION", obj.LEVEL_DESCRIPTION);
                hashtable.Add(":SEQ_NO", obj.SEQ_NO);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.MstBuyerLevel obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.LEVEL_NO))
                    {
                        concast.Append(" AND LEVEL_NO=:LEVEL_NO ");
                        hashtable.Add(":LEVEL_NO", obj.LEVEL_NO);
                    }

                    if (!String.IsNullOrEmpty(obj.LEVEL_DESCRIPTION))
                    {
                        concast.Append(" AND LEVEL_DESCRIPTION=:LEVEL_DESCRIPTION ");
                        hashtable.Add(":LEVEL_DESCRIPTION", obj.LEVEL_DESCRIPTION);
                    }

                    if (!Information.IsNothing(obj.SEQ_NO))
                    {
                        concast.Append(" AND SEQ_NO=:SEQ_NO ");
                        hashtable.Add(":SEQ_NO", obj.SEQ_NO);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                }
                sql = System.String.Format(@" DELETE FROM MST_BUYER_LEVEL ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/

